/**
 * 
 * 起迪科技 Copyright (c) 2014-2018 QiDi,Inc.All Rights Reserved.
 */
package cn.qidisoft.edu.hzjt.controller.forumcontributions;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.FilenameUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSONObject;

import cn.qidisoft.core.common.log.LoggerAdapter;
import cn.qidisoft.core.common.log.LoggerAdapterFactory;
import cn.qidisoft.core.common.pagination.Page;
import cn.qidisoft.core.common.pagination.PaginationBean;
import cn.qidisoft.core.util.DateUtil;
import cn.qidisoft.core.util.StringUtils;
import cn.qidisoft.core.util.file.FileUtil;
import cn.qidisoft.core.util.moffice.excel.ExpExcelUtil;
import cn.qidisoft.core.web.customargument.bind.annotation.Token;
import cn.qidisoft.edu.hzjt.annotation.SysLogger;
import cn.qidisoft.edu.hzjt.constants.Constant;
import cn.qidisoft.edu.hzjt.controller.BaseController;
import cn.qidisoft.edu.hzjt.model.JkyContribution;
import cn.qidisoft.edu.hzjt.model.JkyContributionAtt;
import cn.qidisoft.edu.hzjt.model.JkyContributionReply;
import cn.qidisoft.edu.hzjt.model.ResponseResult;
import cn.qidisoft.edu.hzjt.model.UserEmployee;
import cn.qidisoft.edu.hzjt.service.IJkyContributionAttService;
import cn.qidisoft.edu.hzjt.service.IJkyContributionReplyService;
import cn.qidisoft.edu.hzjt.service.IJkyContributionService;
import cn.qidisoft.edu.hzjt.utils.LogType;

/**
 * 
 * @author hxq
 * @version $Id: forumContributionsController.java, v 0.1 2018年12月5日 下午5:05:11 hxq Exp $
 */
@Controller
@RequestMapping("forumContributions")
public class forumContributionsController {
  protected static final LoggerAdapter LOGGER =
      LoggerAdapterFactory.getLogger(LogType.HZJT_LOGGER.val);
  @Autowired
  private IJkyContributionAttService jkyContributionAttService;
  @Autowired
  private IJkyContributionService jkyContributionService;
  @Autowired
  private IJkyContributionReplyService jkyContributionReplyService;
  private static Map<String, List<JkyContributionAtt>> picMap =
      new HashMap<String, List<JkyContributionAtt>>();

  /**
   * 行政论坛投稿(老师端)
   *
   * @param model
   * @param request
   * @return
   */
  @RequestMapping(value = "/index")
  public String index(ModelMap model, HttpServletRequest request) {
    try {
      request.setAttribute("msg", BaseController.getParameter("msg"));
      BaseController.removeParameter("msg");
    } catch (Exception e) {
      e.printStackTrace();
      return "error/error";
    }
    return "forumContributions/forumContributions_list";
  }

  /**
   * 行政论坛投稿信息列表
   * 
   * @param model
   * @param request
   * @param pageSize
   * @param currentPage
   * @param data
   * @return
   */
  @RequestMapping(value = "/jkyContributionList")
  @ResponseBody
  public ResponseResult jkyContributionList(ModelMap model, HttpServletRequest request,
      @RequestParam(value = "rows", required = false) String pageSize,
      @RequestParam(value = "page", required = false) String currentPage, JkyContribution data) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    ResponseResult result = new ResponseResult();
    try {
      if (loginType == 2) { // 老师
        UserEmployee userEmployee =
            (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        data.setCreatorid(userEmployee.getUid());
        Page page = BaseController.getPage(currentPage, pageSize, request, "createtime", "desc");
        data.setOrderField((String) request.getAttribute("orderField"));
        data.setOrderFlag((String) request.getAttribute("orderFlag"));
        PaginationBean<JkyContribution> paginationBean =
            jkyContributionService.queryJkyContributionPageList(data, page);
        if (paginationBean.getPageList().isEmpty()) {
          result.setRows(new ArrayList<JkyContribution>());
        } else {
          result.setRows(paginationBean.getPageList());
        }
        result.setTotal(paginationBean.getTotalRecords());
      } else {
        result.setRows(new ArrayList<JkyContribution>());
        result.setTotal(0);
      }
      return result;
    } catch (Exception e) {
      result.setRows(new ArrayList<JkyContribution>());
      result.setTotal(0);
      e.printStackTrace();
      LOGGER.error(
          "行政论坛投稿列表信息 jkyContributionList [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
    }
    return result;
  }

  /**
   * 行政论坛投稿跳转页面
   * 
   * @param model
   * @param request
   * @return
   */
  @RequestMapping(value = "/addForumContributionsForward")
  @Token(save = true)
  public String addForumContributionsForward(ModelMap model, HttpServletRequest request) {
    try {
      Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
      if (loginType == 2) { // 老师
        UserEmployee userEmployee =
            (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);

        model.put("name", userEmployee.getName());
        model.put("currentDate", new Date());
        model.put("creatorid", userEmployee.getUid());
        model.put("msg", BaseController.getParameter("msg"));
        BaseController.removeParameter("msg");
      } else {
        BaseController.setParameter("msg", "没权限访问该页面");
        return "redirect:index";
      }
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error(
          "行政论坛投稿信息 addForumContributionsForward [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
    return "forumContributions/addForumContribution";
  }

  /**
   * 删除图片
   * 
   * @param file
   * @param request
   * @param response
   */
  @RequestMapping(value = "/source_upload", method = RequestMethod.POST)
  public @ResponseBody void loadFile(@RequestParam("file") MultipartFile file,
      HttpServletRequest request, HttpServletResponse response) {
    PrintWriter writer = null;
    try {
      writer = response.getWriter();
      List<JkyContributionAtt> list = new ArrayList<JkyContributionAtt>();
      UserEmployee userEmployee =
          (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
      List<JkyContributionAtt> docFileResourceList = new ArrayList<JkyContributionAtt>();
      if (picMap.get(String.valueOf(userEmployee.getUserid())) != null) {
        docFileResourceList = picMap.get(String.valueOf(userEmployee.getUserid()));
      }
      // 本地env配置路径
      String path = Constant.UPLOADPATH;
      JkyContributionAtt docFile = new JkyContributionAtt();
      if (!file.isEmpty()) {
        // 文件的大小
        docFile.setFilesize(String.valueOf(FileUtil.FormetFileSize(Long.valueOf(file.getSize()))));
        String name = file.getOriginalFilename();// 获取上传文件名
        docFile.setFilename(name);
        String uuid = UUID.randomUUID().toString();
        docFile.setFilesize(file.getSize() + "");
        docFile.setContenttype(file.getContentType());
        // 获取文件后缀名称
        String extend = FilenameUtils.getExtension(name);
        docFile.setExtension(extend);
        docFile.setOrders(docFileResourceList.size() + 1);
        // 文件路径
        docFile.setFilepath(Constant.CONTRIBUTIONATT_RESOURCE + "/" + userEmployee.getUid() + "/"
            + DateUtil.formatDate2Str(new Date(), "yyyy-MM-dd"));
        docFile.setInputStream(file.getInputStream());
        docFile.setMufile(file);
        docFile.setFileUuidName(uuid);
        if (docFileResourceList != null && docFileResourceList.size() > 0) {
          docFileResourceList.add(docFile);
          picMap.put(String.valueOf(userEmployee.getUid()), docFileResourceList);
        } else {
          list.add(docFile);
          picMap.put(String.valueOf(userEmployee.getUid()), list);
        }
        LOGGER.info("附件上传成功！");
        JkyContributionAtt docFile2 = new JkyContributionAtt();
        docFile2.setFilename(docFile.getFilename());
        docFile2.setFilepath(docFile.getFilepath());
        writer = (PrintWriter) response.getWriter();
        String json = JSONObject.toJSONString(docFile2);
        writer.write(json);
        writer.flush();
        writer.close();
      }
    } catch (IOException e) {
      e.printStackTrace();
      writer.write("上传失败");
      writer.flush();
      writer.close();
    }
  }

  /**
   * 
   * 新增行政论坛投稿信息
   * 
   * @param model
   * @param request
   * @param JkyContribution
   * @return
   */
  @RequestMapping(value = "/addForumContributions")
  @Token(remove = true, path = "index")
  @SysLogger(description = "新增行政论坛投稿信息", moduleName = "行政论坛投稿", method = "新增")
  public String addForumContributions(ModelMap model, HttpServletRequest request,
      JkyContribution jkyContribution) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    try {
      if (loginType == 2) { // 老师
        UserEmployee userEmployee =
            (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        jkyContribution.setTargettype(1);
        jkyContribution.setCreatetime(
            DateUtil.parseStr2Date(jkyContribution.getEndTime(), "yyyy-MM-dd hh:mm:ss"));
        if (picMap.get(String.valueOf(userEmployee.getUid())) != null) {
          List<JkyContributionAtt> docFileResourceList =
              picMap.get(String.valueOf(userEmployee.getUid()));
          MultipartFile file = null;
          if (docFileResourceList != null && !docFileResourceList.isEmpty()) {
            jkyContribution.setDocnum(docFileResourceList.size());
            List<JkyContributionAtt> contributionAttList = new ArrayList<JkyContributionAtt>();
            for (JkyContributionAtt r : docFileResourceList) {
              file = r.getMufile();
              // String name = file.getOriginalFilename();// 获取上传文件名
              InputStream in = r.getInputStream();// 获取文件对象
              // int pos = name.lastIndexOf(".");
              // String lastname = name.substring(pos, name.length());
              // 文件保存的路径
              String savePath = Constant.UPLOADPATH + "/" + r.getFilepath();
              FileUtil.saveFile(savePath, in, r.getFileUuidName() + "." + r.getExtension());
              r.setFilepath(r.getFilepath() + "/" + r.getFileUuidName() + "." + r.getExtension());
              contributionAttList.add(r);
            }
            jkyContribution.setJkyContributionAttList(contributionAttList);
          }
        } else {
          jkyContribution.setDocnum(0);
        }
        int tgid = jkyContributionService.insert(jkyContribution);
        String flag = request.getParameter("flag");
        if (tgid >= 1 && !StringUtils.isNullValue(flag) && "1".equals(flag)) { // 新增跳转到修改页面
          BaseController.setParameter("msg", "保存成功");
          return "redirect:modiftyForumContributionsForWard?tgid=" + tgid;
        } else if (tgid >= 1 && !StringUtils.isNullValue(flag) && "2".equals(flag)) { // 新增且继续新增
          BaseController.setParameter("msg", "保存成功");
          return "redirect:addForumContributionsForward";
        } else {
          BaseController.setParameter("msg", "保存失败");
          return "redirect:index";
        }
      } else {
        BaseController.setParameter("msg", "没权限访问该页面");
        return "redirect:index";
      }
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error(
          "新增行政论坛投稿信息 addForumContributions [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
  }

  /**
   * 删除服务器的文件
   * 
   * @param request
   * @return
   */
  @RequestMapping(value = "/deleteContributionFile", method = RequestMethod.POST)
  @SysLogger(description = "删除行政论坛投稿附件信息", moduleName = "行政论坛投稿", method = "删除")
  public @ResponseBody Map<String, Object> deleteContributionFile(HttpServletRequest request) {
    Map<String, Object> dataMap = new HashMap<String, Object>();
    try {
      UserEmployee userEmployee =
          (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);

      String filepath = request.getParameter("filepath");
      LOGGER.info("文件的原始路径===" + filepath);
      // 文件名无后缀
      String fileNoSuffix = null;

      if (filepath.indexOf("prefix") == -1) {
        // 文件的文件名称
        // fileNoSuffix = filepath.split(",")[0];
        fileNoSuffix = filepath;
        // String sec = filepath.split(",")[1];
        // 文件的后缀
        // String suffix = sec.substring(sec.indexOf("."));
        // 文件名无后缀加上后缀
        // filename = fileNoSuffix + suffix;
        // 文件的全路径
        // fullpath = path + "/" + fileNoSuffix;
        // fullpath = path + "/" + filepath.split(",")[1];
        // FileUtil.deleteFile(fullpath, filename);//删除文件目录下面的文件
        // FileUtils.forceDelete(new File(fullpath)); //删除文件目录
      } else {
        return dataMap;
      }
      List<JkyContributionAtt> noticeNewsFilepathList =
          picMap.get(String.valueOf(userEmployee.getUserid()));

      // 删除list里面前台删除的前台信息图片附件表
      if (noticeNewsFilepathList != null && !noticeNewsFilepathList.isEmpty()) {
        for (JkyContributionAtt noticenewsfilepath : noticeNewsFilepathList) {
          if (noticenewsfilepath.getFilename().equals(fileNoSuffix)) {
            noticeNewsFilepathList.remove(noticenewsfilepath);
            break;
          }
        }
      }
      // 先删除
      picMap.remove(userEmployee.getUserid());
      // 后添加
      picMap.put(String.valueOf(userEmployee.getUserid()), noticeNewsFilepathList);
      dataMap.put("success", "0000");
      return dataMap;
    } catch (Exception e) {
      dataMap.put("success", "-9999");
      return dataMap;
    }
  }

  /**
   * 
   * 政论坛投稿信息 修改跳转页面
   * 
   * @param model
   * @param request
   * @param id
   * @return
   */
  @RequestMapping(value = "/modiftyForumContributionsForWard", method = RequestMethod.GET)
  public String modiftyForumContributionsForWard(ModelMap model, HttpServletRequest request,
      @RequestParam(value = "tgid") Integer id) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    try {
      JkyContribution jkyContribution = new JkyContribution();
      if (loginType == 2) { // 教师
        UserEmployee userEmployee =
            (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        List<JkyContributionAtt> contributionAttList = new ArrayList<JkyContributionAtt>();
        List<JkyContributionReply> contributionReplyList = new ArrayList<JkyContributionReply>();
        if (id != null) {
          jkyContribution = jkyContributionService.queryByPK(id);
          if (jkyContribution != null) {
            contributionAttList = jkyContributionAttService.queryContributionAttList(id);
            contributionReplyList = jkyContributionReplyService.queryContributionReplyList(id);
          }
        }
        model.put("jkyContribution", jkyContribution);
        model.put("contributionAttList", contributionAttList);
        model.put("contributionReplyList", contributionReplyList);
        Integer isReply = 0;
        if (contributionReplyList != null && !contributionReplyList.isEmpty()) {
          for (JkyContributionReply r : contributionReplyList) {
            if (r.getReplytype().intValue() == 1) { // 判断是否有反馈意见
              isReply = 1;
              break;
            }
          }
        }
        model.put("isReply", isReply);
        model.put("msg", BaseController.getParameter("msg"));
        BaseController.removeParameter("msg");
        return "forumContributions/updateForumContribution";
      } else {
        BaseController.setParameter("msg", "没权限访问该页面");
        return "redirect:index";
      }
    } catch (Exception e) {
      LOGGER.error("修改政论坛投稿信息 modiftyForumContributionsForWard [{}] error,"
          + this.getClass().getName() + "=[{}]", this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }

  }

  /**
   * 修改行政论坛投稿信息
   * 
   * @param model
   * @param request
   * @param jkyContribution
   * @return
   */
  @SysLogger(description = "修改行政论坛投稿信息", moduleName = "行政论坛投稿", method = "修改")
  @RequestMapping(value = "/modiftyContributions", method = RequestMethod.POST)
  public String modiftyContributions(ModelMap model, HttpServletRequest request,
      JkyContribution jkyContribution) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    try {
      if (loginType == 2) { // 教师
        UserEmployee userEmployee =
            (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        jkyContribution.setTargettype(1);
        List<JkyContributionAtt> oldContributionAttList = new ArrayList<JkyContributionAtt>();
        if (jkyContribution != null && jkyContribution.getTgid() != null) {
          oldContributionAttList =
              jkyContributionAttService.queryContributionAttList(jkyContribution.getTgid());
        }
        if (picMap.get(String.valueOf(userEmployee.getUid())) != null) {
          List<JkyContributionAtt> docFileResourceList =
              picMap.get(String.valueOf(userEmployee.getUid()));
          MultipartFile file = null;
          if (docFileResourceList != null && !docFileResourceList.isEmpty()) {
            List<JkyContributionAtt> contributionAttList = new ArrayList<JkyContributionAtt>();
            for (JkyContributionAtt r : docFileResourceList) {
              file = r.getMufile();
              // String name = file.getOriginalFilename();// 获取上传文件名
              InputStream in = r.getInputStream();// 获取文件对象
              // int pos = name.lastIndexOf(".");
              // String lastname = name.substring(pos, name.length());
              // 文件保存的路径
              String savePath = Constant.UPLOADPATH + "/" + r.getFilepath();
              FileUtil.saveFile(savePath, in, r.getFileUuidName() + "." + r.getExtension());
              r.setFilepath(r.getFilepath() + "/" + r.getFileUuidName() + "." + r.getExtension());
              contributionAttList.add(r);
            }
            jkyContribution.setDocnum(oldContributionAttList.size() + contributionAttList.size());
            jkyContribution.setJkyContributionAttList(contributionAttList);
          }
        } else {
          jkyContribution.setDocnum(oldContributionAttList.size());
        }
        int num = jkyContributionService.updateByPK(jkyContribution);
        if (num >= 1) {
          BaseController.setParameter("msg", "保存成功");
        } else {
          BaseController.setParameter("msg", "保存失败");
        }
        return "redirect:modiftyForumContributionsForWard?tgid=" + jkyContribution.getTgid();
      } else {
        BaseController.setParameter("msg", "没权限访问该页面");
        return "redirect:index";
      }
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error(
          "修改政论坛投稿信息 modiftyContributions [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
  }

  /**
   * 回复行政论坛投稿信息
   * 
   * @param model
   * @param request
   * @param jkyContribution
   * @return
   */
  @SysLogger(description = "反馈或回复行政论坛投稿信息", moduleName = "行政论坛投稿", method = "新增")
  @RequestMapping(value = "/modiftyContributionsReply", method = RequestMethod.POST)
  public String modiftyContributionsReply(ModelMap model, HttpServletRequest request,
      @RequestParam(value = "tgid", required = true) Integer tgid,
      @RequestParam(value = "replytype", required = true) Integer replytype,
      @RequestParam(value = "replycomments", required = true) String replycomments) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    try {
      if (loginType == 2) { // 教师
        UserEmployee userEmployee =
            (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        JkyContributionReply jkyContributionReply = new JkyContributionReply();
        jkyContributionReply.setParentid(tgid);
        jkyContributionReply.setReplytype(replytype);
        jkyContributionReply.setReplycomments(replycomments);
        jkyContributionReply.setReplyerid(userEmployee.getUid());
        jkyContributionReply.setReplyername(StringUtils.isNullValue(userEmployee.getName()) == true
            ? userEmployee.getUserid() : userEmployee.getName());
        jkyContributionReply.setReplytime(new Date());
        int num = jkyContributionReplyService.insert(jkyContributionReply);
        if (num >= 1) {
          BaseController.setParameter("msg", "保存成功");
        } else {
          BaseController.setParameter("msg", "保存失败");
        }
        if (replytype == 2) {
          return "redirect:modiftyForumContributionsForWard?tgid=" + tgid;
        } else if (replytype == 1) {
          return "redirect:modiftyManagerContributionsForWard?tgid=" + tgid;
        }
      } else {
        BaseController.setParameter("msg", "没权限访问该页面");
        if (replytype == 2) {
          return "redirect:index";
        } else if (replytype == 1) {
          return "redirect:indexManager";
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error(
          "修改政论坛投稿信息 modiftyContributionsReply [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
    return null;
  }

  /**
   * 删除附件
   * 
   * @param file
   * @param request
   * @param response
   */
  @RequestMapping(value = "/deleteFileSource", method = RequestMethod.POST)
  @SysLogger(description = "删除行政论坛投稿附件信息", moduleName = "行政论坛投稿", method = "删除")
  public @ResponseBody Map<String, Object> deleteFileSource(@RequestParam("id") Integer id,
      HttpServletRequest request, HttpServletResponse response) {
    Map<String, Object> dataMap = new HashMap<String, Object>();
    try {
      if (id != null) {
        // 查询附件表信息
        JkyContributionAtt jkyContributionAtt = jkyContributionAttService.queryByPK(id);
        if (jkyContributionAtt != null) {
          int num = jkyContributionAttService.deleteByPK(jkyContributionAtt);
          if (num >= 1) {
            FileUtil.deleteFile(Constant.UPLOADPATH + "/" + jkyContributionAtt.getFilepath());
          }
        }
      }
      dataMap.put("success", "0000");
    } catch (Exception e) {
      LOGGER.error("调用services网络异常", e);
      dataMap.put("success", "-9999");
    }
    return dataMap;
  }

  /**
   * 
   * 删除行政论坛投稿信息
   * 
   * @param model
   * @param request
   * @return
   */
  @SysLogger(description = "删除行政论坛投稿信息", moduleName = "行政论坛投稿", method = "删除")
  @RequestMapping(value = "/deleteForumContributions", method = RequestMethod.POST)
  public String deleteForumContributions(ModelMap model, HttpServletRequest request) {
    try {
      String[] idList = request.getParameter("idList").split(",");
      if (idList.length >= 1) {
        List<JkyContributionAtt> contributionAttList =
            jkyContributionService.deleteForumContributions(idList);
        if (contributionAttList != null && !contributionAttList.isEmpty()) {
          for (JkyContributionAtt att : contributionAttList) {
            FileUtil.deleteFile(Constant.UPLOADPATH + "/" + att.getFilepath());
          }
        }
        BaseController.setParameter("msg", "删除成功");
      } else {
        BaseController.setParameter("msg", "删除失败");
      }
      return "redirect:index";
    } catch (Exception e) {
      LOGGER.error(e.getMessage(), e);
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
  }

  /**
   * 行政论坛投稿(管理端)
   *
   * @param model
   * @param request
   * @return
   */
  @RequestMapping(value = "/indexManager")
  public String indexManager(ModelMap model, HttpServletRequest request) {
    try {
      request.setAttribute("msg", BaseController.getParameter("msg"));
      BaseController.removeParameter("msg");
    } catch (Exception e) {
      e.printStackTrace();
      return "error/error";
    }
    return "forumContributions/contributions_manager_list";
  }

  /**
   * 行政论坛投稿信息列表（管理端）
   * 
   * @param model
   * @param request
   * @param pageSize
   * @param currentPage
   * @param data
   * @return
   */
  @RequestMapping(value = "/jkyContributionManagerList")
  @ResponseBody
  public ResponseResult jkyContributionManagerList(ModelMap model, HttpServletRequest request,
      @RequestParam(value = "rows", required = false) String pageSize,
      @RequestParam(value = "page", required = false) String currentPage, JkyContribution data) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    ResponseResult result = new ResponseResult();
    try {
      if (loginType == 2) { // 老师
        UserEmployee userEmployee =
            (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        // data.setCreatorid(userEmployee.getUid());
        Page page = BaseController.getPage(currentPage, pageSize, request, "createtime", "desc");
        data.setOrderField((String) request.getAttribute("orderField"));
        data.setOrderFlag((String) request.getAttribute("orderFlag"));
        PaginationBean<JkyContribution> paginationBean =
            jkyContributionService.queryJkyContributionManagerPageList(data, page);
        if (paginationBean.getPageList().isEmpty()) {
          result.setRows(new ArrayList<JkyContribution>());
        } else {
          for (JkyContribution jky : paginationBean.getPageList()) {
            jky.setBeginTime(DateUtil.formatDate2Str(jky.getCreatetime(), "yyyy-MM-dd HH:mm:ss"));
            jky.setName(jky.getCreatorname());
          }
          result.setRows(paginationBean.getPageList());
        }
        result.setTotal(paginationBean.getTotalRecords());
      } else {
        result.setRows(new ArrayList<JkyContribution>());
        result.setTotal(0);
      }
      return result;
    } catch (Exception e) {
      result.setRows(new ArrayList<JkyContribution>());
      result.setTotal(0);
      e.printStackTrace();
      LOGGER.error(
          "行政论坛投稿列表(管理端)信息 jkyContributionList [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
    }
    return result;
  }

  /**
   * 
   * 政论坛投稿信息 修改跳转页面(管理端)
   * 
   * @param model
   * @param request
   * @param id
   * @return
   */
  @RequestMapping(value = "/modiftyManagerContributionsForWard", method = RequestMethod.GET)
  public String modiftyManagerContributionsForWard(ModelMap model, HttpServletRequest request,
      @RequestParam(value = "tgid") Integer id) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    try {
      JkyContribution jkyContribution = new JkyContribution();
      if (loginType == 2) { // 教师
        UserEmployee userEmployee =
            (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        List<JkyContributionAtt> contributionAttList = new ArrayList<JkyContributionAtt>();
        List<JkyContributionReply> contributionReplyList = new ArrayList<JkyContributionReply>();
        if (id != null) {
          jkyContribution = jkyContributionService.queryByPK(id);
          if (jkyContribution != null) {
            contributionAttList = jkyContributionAttService.queryContributionAttList(id);
            contributionReplyList = jkyContributionReplyService.queryContributionReplyList(id);
          }
        }
        model.put("jkyContribution", jkyContribution);
        model.put("contributionAttList", contributionAttList);
        model.put("contributionReplyList", contributionReplyList);
        model.put("msg", BaseController.getParameter("msg"));
        BaseController.removeParameter("msg");
        return "forumContributions/updateManagerContribution";
      } else {
        BaseController.setParameter("msg", "没权限访问该页面");
        return "redirect:indexManager";
      }
    } catch (Exception e) {
      LOGGER.error("修改政论坛投稿信息（管理端） modiftyManagerContributionsForWard [{}] error,"
          + this.getClass().getName() + "=[{}]", this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }

  }

  /**
   * 导出政论坛投稿信息(管理端)
   * 
   * @param model
   * @param request
   */
  @RequestMapping(value = "/exportManagerContributions")
  public String exportManagerContributions(ModelMap model, HttpServletRequest request,
      JkyContribution jkyContribution, HttpServletResponse response) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    try {
      String[][] title_name = {{"投稿人", "投稿日期", "稿件数量", "主题", "备注"}};
      String[] title_style = {"hwzs_16_bold_25", "kt_12_bold_18", "st_12_r_20", "st_12_n_20"};
      String fileName = "行政论坛投稿信息";
      String[] remark = {""};
      List<Map<String, Object>> exportlist = new ArrayList<Map<String, Object>>();
      if (loginType == 2) { // 老师
        UserEmployee userEmployee =
            (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        Page page = BaseController.getPage("0", "0", request, "createtime", "desc");
        jkyContribution.setOrderField((String) request.getAttribute("orderField"));
        jkyContribution.setOrderFlag((String) request.getAttribute("orderFlag"));
        List<JkyContribution> list =
            jkyContributionService.exportJkyContributionManagerPageList(jkyContribution);
        if (!list.isEmpty()) {
          for (JkyContribution res : list) {
            Map<String, Object> map = new LinkedHashMap<String, Object>();
            map.put("creatorname", res.getCreatorname());
            map.put("createtime", DateUtil.formatDate2Str(res.getCreatetime(), "yyyy-MM-dd hh:mm"));
            map.put("docnum", res.getDocnum());
            map.put("subject", res.getSubject());
            map.put("remark", res.getRemark());
            exportlist.add(map);
          }
        }
      }
      HSSFWorkbook wb =
          ExpExcelUtil.getWorkBookExcel(title_name, title_style, 100, remark, fileName, exportlist);
      response.reset();
      response.setContentType("application/vnd.ms-excel;charset=utf-8");
      response.setHeader("Content-Disposition",
          "attachment;filename=" + new String((fileName + ".xls").getBytes(), "iso-8859-1"));
      response.setDateHeader("Expires", 0);
      ServletOutputStream os = response.getOutputStream();
      wb.write(os);
      os.flush();
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error("导出政论坛投稿信息（管理端） exportManagerContributions [{}] error,"
          + this.getClass().getName() + "=[{}]", this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
    return null;
  }

  /**
   * 年度科研作业(老师端)
   *
   * @param model
   * @param request
   * @return
   */
  @RequestMapping(value = "/indexScientificJob")
  public String indexScientificJob(ModelMap model, HttpServletRequest request) {
    try {
      request.setAttribute("msg", BaseController.getParameter("msg"));
      BaseController.removeParameter("msg");
    } catch (Exception e) {
      e.printStackTrace();
      return "error/error";
    }
    return "forumContributions/scientificJob_list";
  }

  /**
   * 年度科研作业列表(老师端)
   * 
   * @param model
   * @param request
   * @param pageSize
   * @param currentPage
   * @param data
   * @return
   */
  @RequestMapping(value = "/jkyScientificJobList")
  @ResponseBody
  public ResponseResult jkyScientificJobList(ModelMap model, HttpServletRequest request,
      @RequestParam(value = "rows", required = false) String pageSize,
      @RequestParam(value = "page", required = false) String currentPage, JkyContribution data) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    ResponseResult result = new ResponseResult();
    try {
      if (loginType == 2) { // 老师
        UserEmployee userEmployee =
            (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        data.setCreatorid(userEmployee.getUid());
        Page page = BaseController.getPage(currentPage, pageSize, request, "createtime", "desc");
        data.setOrderField((String) request.getAttribute("orderField"));
        data.setOrderFlag((String) request.getAttribute("orderFlag"));
        PaginationBean<JkyContribution> paginationBean =
            jkyContributionService.queryScientificJobPageList(data, page);
        if (paginationBean.getPageList().isEmpty()) {
          result.setRows(new ArrayList<JkyContribution>());
        } else {
          for (JkyContribution jky : paginationBean.getPageList()) {
            jky.setBeginTime(DateUtil.formatDate2Str(jky.getCreatetime(), "yyyy-MM-dd HH:mm:ss"));
          }
          result.setRows(paginationBean.getPageList());
        }
        result.setTotal(paginationBean.getTotalRecords());
      } else {
        result.setRows(new ArrayList<JkyContribution>());
        result.setTotal(0);
      }
      return result;
    } catch (Exception e) {
      result.setRows(new ArrayList<JkyContribution>());
      result.setTotal(0);
      e.printStackTrace();
      LOGGER.error(
          "年度科研作业列表(老师端)信息 jkyScientificJobList [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
    }
    return result;
  }

  /**
   * 年度科研作业列表(老师端)跳转页面
   * 
   * @param model
   * @param request
   * @return
   */
  @RequestMapping(value = "/addScientificJobForward")
  @Token(save = true)
  public String addScientificJobForward(ModelMap model, HttpServletRequest request) {
    try {
      Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
      if (loginType == 2) { // 老师
        UserEmployee userEmployee =
            (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        model.put("name", userEmployee.getName());
        model.put("currentDate", new Date());
        model.put("creatorid", userEmployee.getUid());
        model.put("msg", BaseController.getParameter("msg"));
        BaseController.removeParameter("msg");
      } else {
        BaseController.setParameter("msg", "没权限访问该页面");
        return "redirect:indexScientificJob";
      }
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error("年度科研作业列表(老师端)信息 addScientificJobForward [{}] error," + this.getClass().getName()
          + "=[{}]", this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
    return "forumContributions/addScientificJob";
  }

  /**
   * 年度科研作业上传图片
   * 
   * @param file
   * @param request
   * @param response
   */
  @RequestMapping(value = "/uploadScientificJob", method = RequestMethod.POST)
  public @ResponseBody void uploadScientificJob(@RequestParam("file") MultipartFile file,
      HttpServletRequest request, HttpServletResponse response) {
    PrintWriter writer = null;
    try {
      writer = response.getWriter();
      List<JkyContributionAtt> list = new ArrayList<JkyContributionAtt>();
      UserEmployee userEmployee =
          (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
      List<JkyContributionAtt> docFileResourceList = new ArrayList<JkyContributionAtt>();
      if (picMap.get(String.valueOf(userEmployee.getUserid())) != null) {
        docFileResourceList = picMap.get(String.valueOf(userEmployee.getUserid()));
      }
      // 本地env配置路径
      String path = Constant.UPLOADPATH;
      JkyContributionAtt docFile = new JkyContributionAtt();
      if (!file.isEmpty()) {
        // 文件的大小
        docFile.setFilesize(String.valueOf(FileUtil.FormetFileSize(Long.valueOf(file.getSize()))));
        String name = file.getOriginalFilename();// 获取上传文件名
        docFile.setFilename(name);
        String uuid = UUID.randomUUID().toString();
        docFile.setFilesize(file.getSize() + "");
        docFile.setContenttype(file.getContentType());
        // 获取文件后缀名称
        String extend = FilenameUtils.getExtension(name);
        docFile.setExtension(extend);
        docFile.setOrders(docFileResourceList.size() + 1);
        // 文件路径
        docFile.setFilepath(Constant.CONTRIBUTIONATT_RESOURCE2 + "/" + userEmployee.getUid() + "/"
            + DateUtil.formatDate2Str(new Date(), "yyyy-MM-dd"));
        docFile.setInputStream(file.getInputStream());
        docFile.setMufile(file);
        docFile.setFileUuidName(uuid);
        if (docFileResourceList != null && docFileResourceList.size() > 0) {
          docFileResourceList.add(docFile);
          picMap.put(String.valueOf(userEmployee.getUid()), docFileResourceList);
        } else {
          list.add(docFile);
          picMap.put(String.valueOf(userEmployee.getUid()), list);
        }
        LOGGER.info("附件上传成功！");
        JkyContributionAtt docFile2 = new JkyContributionAtt();
        docFile2.setFilename(docFile.getFilename());
        docFile2.setFilepath(docFile.getFilepath());
        writer = (PrintWriter) response.getWriter();
        String json = JSONObject.toJSONString(docFile2);
        writer.write(json);
        writer.flush();
        writer.close();
      }
    } catch (IOException e) {
      e.printStackTrace();
      writer.write("上传失败");
      writer.flush();
      writer.close();
    }
  }

  /**
   * 
   * 新增年度科研作业信息
   * 
   * @param model
   * @param request
   * @param JkyContribution
   * @return
   */
  @RequestMapping(value = "/addScientificJob")
  @Token(remove = true, path = "indexScientificJob")
  @SysLogger(description = "新增年度科研作业信息", moduleName = "年度科研作业", method = "新增")
  public String addScientificJob(ModelMap model, HttpServletRequest request,
      JkyContribution jkyContribution) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    try {
      if (loginType == 2) { // 老师
        UserEmployee userEmployee =
            (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        jkyContribution.setTargettype(2);
        jkyContribution.setCreatetime(
            DateUtil.parseStr2Date(jkyContribution.getEndTime(), "yyyy-MM-dd hh:mm:ss"));
        if (picMap.get(String.valueOf(userEmployee.getUid())) != null) {
          List<JkyContributionAtt> docFileResourceList =
              picMap.get(String.valueOf(userEmployee.getUid()));
          MultipartFile file = null;
          if (docFileResourceList != null && !docFileResourceList.isEmpty()) {
            jkyContribution.setDocnum(docFileResourceList.size());
            List<JkyContributionAtt> contributionAttList = new ArrayList<JkyContributionAtt>();
            for (JkyContributionAtt r : docFileResourceList) {
              file = r.getMufile();
              // String name = file.getOriginalFilename();// 获取上传文件名
              InputStream in = r.getInputStream();// 获取文件对象
              // int pos = name.lastIndexOf(".");
              // String lastname = name.substring(pos, name.length());
              // 文件保存的路径
              String savePath = Constant.UPLOADPATH + "/" + r.getFilepath();
              FileUtil.saveFile(savePath, in, r.getFileUuidName() + "." + r.getExtension());
              r.setFilepath(r.getFilepath() + "/" + r.getFileUuidName() + "." + r.getExtension());
              contributionAttList.add(r);
            }
            jkyContribution.setJkyContributionAttList(contributionAttList);
          }
        } else {
          jkyContribution.setDocnum(0);
        }
        int tgid = jkyContributionService.insert(jkyContribution);
        String flag = request.getParameter("flag");
        if (tgid >= 1 && !StringUtils.isNullValue(flag) && "1".equals(flag)) { // 新增跳转到修改页面
          BaseController.setParameter("msg", "保存成功");
          return "redirect:modiftyScientificJobForWard?tgid=" + tgid;
        } else if (tgid >= 1 && !StringUtils.isNullValue(flag) && "2".equals(flag)) { // 新增且继续新增
          BaseController.setParameter("msg", "保存成功");
          return "redirect:addScientificJobForward";
        } else {
          BaseController.setParameter("msg", "保存失败");
          return "redirect:indexScientificJob";
        }
      } else {
        BaseController.setParameter("msg", "没权限访问该页面");
        return "redirect:indexScientificJob";
      }
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error("新增年度科研作业信息 addScientificJob [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
  }

  /**
   * 删除年度科研作业附件信息
   * 
   * @param request
   * @return
   */
  @RequestMapping(value = "/deleteScientificJobFile", method = RequestMethod.POST)
  @SysLogger(description = "删除年度科研作业附件信息", moduleName = "年度科研作业", method = "删除")
  public @ResponseBody Map<String, Object> deleteScientificJobFile(HttpServletRequest request) {
    Map<String, Object> dataMap = new HashMap<String, Object>();
    try {
      UserEmployee userEmployee =
          (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);

      String filepath = request.getParameter("filepath");
      LOGGER.info("文件的原始路径===" + filepath);
      // 文件名无后缀
      String fileNoSuffix = null;

      if (filepath.indexOf("prefix") == -1) {
        // 文件的文件名称
        // fileNoSuffix = filepath.split(",")[0];
        fileNoSuffix = filepath;
        // String sec = filepath.split(",")[1];
        // 文件的后缀
        // String suffix = sec.substring(sec.indexOf("."));
        // 文件名无后缀加上后缀
        // filename = fileNoSuffix + suffix;
        // 文件的全路径
        // fullpath = path + "/" + fileNoSuffix;
        // fullpath = path + "/" + filepath.split(",")[1];
        // FileUtil.deleteFile(fullpath, filename);//删除文件目录下面的文件
        // FileUtils.forceDelete(new File(fullpath)); //删除文件目录
      } else {
        return dataMap;
      }
      List<JkyContributionAtt> noticeNewsFilepathList =
          picMap.get(String.valueOf(userEmployee.getUserid()));

      // 删除list里面前台删除的前台信息图片附件表
      if (noticeNewsFilepathList != null && !noticeNewsFilepathList.isEmpty()) {
        for (JkyContributionAtt noticenewsfilepath : noticeNewsFilepathList) {
          if (noticenewsfilepath.getFilename().equals(fileNoSuffix)) {
            noticeNewsFilepathList.remove(noticenewsfilepath);
            break;
          }
        }
      }
      // 先删除
      picMap.remove(userEmployee.getUserid());
      // 后添加
      picMap.put(String.valueOf(userEmployee.getUserid()), noticeNewsFilepathList);
      dataMap.put("success", "0000");
      return dataMap;
    } catch (Exception e) {
      dataMap.put("success", "-9999");
      return dataMap;
    }
  }

  /**
   * 
   * 年度科研作业信息 修改跳转页面
   * 
   * @param model
   * @param request
   * @param id
   * @return
   */
  @RequestMapping(value = "/modiftyScientificJobForWard", method = RequestMethod.GET)
  public String modiftyScientificJobForWard(ModelMap model, HttpServletRequest request,
      @RequestParam(value = "tgid") Integer id) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    try {
      JkyContribution jkyContribution = new JkyContribution();
      if (loginType == 2) { // 教师
        UserEmployee userEmployee =
            (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        List<JkyContributionAtt> contributionAttList = new ArrayList<JkyContributionAtt>();
        List<JkyContributionReply> contributionReplyList = new ArrayList<JkyContributionReply>();
        if (id != null) {
          jkyContribution = jkyContributionService.queryByPK(id);
          if (jkyContribution != null) {
            contributionAttList = jkyContributionAttService.queryContributionAttList(id);
            contributionReplyList = jkyContributionReplyService.queryContributionReplyList(id);
          }
        }
        model.put("jkyContribution", jkyContribution);
        model.put("contributionAttList", contributionAttList);
        model.put("contributionReplyList", contributionReplyList);
        Integer isReply = 0;
        if (contributionReplyList != null && !contributionReplyList.isEmpty()) {
          for (JkyContributionReply r : contributionReplyList) {
            if (r.getReplytype().intValue() == 1) { // 判断是否有反馈意见
              isReply = 1;
              break;
            }
          }
        }
        model.put("isReply", isReply);
        model.put("msg", BaseController.getParameter("msg"));
        BaseController.removeParameter("msg");
        return "forumContributions/updateScientificJob";
      } else {
        BaseController.setParameter("msg", "没权限访问该页面");
        return "redirect:indexScientificJob";
      }
    } catch (Exception e) {
      LOGGER.error("修改政论坛投稿信息 modiftyForumContributionsForWard [{}] error,"
          + this.getClass().getName() + "=[{}]", this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }

  }

  /**
   * 修改年度科研作业信息
   * 
   * @param model
   * @param request
   * @param jkyContribution
   * @return
   */
  @SysLogger(description = "修改行政论坛投稿信息", moduleName = "年度科研作业信息", method = "修改")
  @RequestMapping(value = "/modiftyScientificJob", method = RequestMethod.POST)
  public String modiftyScientificJob(ModelMap model, HttpServletRequest request,
      JkyContribution jkyContribution) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    try {
      if (loginType == 2) { // 教师
        UserEmployee userEmployee =
            (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        jkyContribution.setTargettype(2);
        List<JkyContributionAtt> oldContributionAttList = new ArrayList<JkyContributionAtt>();
        if (jkyContribution != null && jkyContribution.getTgid() != null) {
          oldContributionAttList =
              jkyContributionAttService.queryContributionAttList(jkyContribution.getTgid());
        }
        if (picMap.get(String.valueOf(userEmployee.getUid())) != null) {
          List<JkyContributionAtt> docFileResourceList =
              picMap.get(String.valueOf(userEmployee.getUid()));
          MultipartFile file = null;
          if (docFileResourceList != null && !docFileResourceList.isEmpty()) {
            List<JkyContributionAtt> contributionAttList = new ArrayList<JkyContributionAtt>();
            for (JkyContributionAtt r : docFileResourceList) {
              file = r.getMufile();
              // String name = file.getOriginalFilename();// 获取上传文件名
              InputStream in = r.getInputStream();// 获取文件对象
              // int pos = name.lastIndexOf(".");
              // String lastname = name.substring(pos, name.length());
              // 文件保存的路径
              String savePath = Constant.UPLOADPATH + "/" + r.getFilepath();
              FileUtil.saveFile(savePath, in, r.getFileUuidName() + "." + r.getExtension());
              r.setFilepath(r.getFilepath() + "/" + r.getFileUuidName() + "." + r.getExtension());
              contributionAttList.add(r);
            }
            jkyContribution.setDocnum(oldContributionAttList.size() + contributionAttList.size());
            jkyContribution.setJkyContributionAttList(contributionAttList);
          }
        } else {
          jkyContribution.setDocnum(oldContributionAttList.size());
        }
        int num = jkyContributionService.updateByPK(jkyContribution);
        if (num >= 1) {
          BaseController.setParameter("msg", "保存成功");
        } else {
          BaseController.setParameter("msg", "保存失败");
        }
        return "redirect:modiftyScientificJobForWard?tgid=" + jkyContribution.getTgid();
      } else {
        BaseController.setParameter("msg", "没权限访问该页面");
        return "redirect:indexScientificJob";
      }
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error(
          "修改行政论坛投稿信息 modiftyScientificJob [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
  }

  /**
   * 回复行年度科研作业信息
   * 
   * @param model
   * @param request
   * @param jkyContribution
   * @return
   */
  @SysLogger(description = "反馈或回复年度科研作业信息", moduleName = "年度科研作业信息", method = "新增")
  @RequestMapping(value = "/modiftyScientificJobReply", method = RequestMethod.POST)
  public String modiftyScientificJobReply(ModelMap model, HttpServletRequest request,
      @RequestParam(value = "tgid", required = true) Integer tgid,
      @RequestParam(value = "replytype", required = true) Integer replytype,
      @RequestParam(value = "replycomments", required = true) String replycomments) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    try {
      if (loginType == 2) { // 教师
        UserEmployee userEmployee =
            (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        JkyContributionReply jkyContributionReply = new JkyContributionReply();
        jkyContributionReply.setParentid(tgid);
        jkyContributionReply.setReplytype(replytype);
        jkyContributionReply.setReplycomments(replycomments);
        jkyContributionReply.setReplyerid(userEmployee.getUid());
        jkyContributionReply.setReplyername(StringUtils.isNullValue(userEmployee.getName()) == true
            ? userEmployee.getUserid() : userEmployee.getName());
        jkyContributionReply.setReplytime(new Date());
        int num = jkyContributionReplyService.insert(jkyContributionReply);
        if (num >= 1) {
          BaseController.setParameter("msg", "保存成功");
        } else {
          BaseController.setParameter("msg", "保存失败");
        }
        if (replytype == 2) {
          return "redirect:modiftyScientificJobForWard?tgid=" + tgid;
        } else if (replytype == 1) {
          return "redirect:modiftyManagerScientificJobForWard?tgid=" + tgid;
        }
      } else {
        BaseController.setParameter("msg", "没权限访问该页面");
        if (replytype == 2) {
          return "redirect:indexScientificJob";
        } else if (replytype == 1) {
          return "redirect:indexManagerScientificJob";
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error(
          "回复行年度科研作业信息 modiftyScientificJobReply [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
    return null;
  }

  /**
   * 删除年度科研作业附件
   * 
   * @param file
   * @param request
   * @param response
   */
  @RequestMapping(value = "/deleteScientificJobFileSource", method = RequestMethod.POST)
  @SysLogger(description = "删除年度科研作业附件信息", moduleName = "年度科研作业信息", method = "删除")
  public @ResponseBody Map<String, Object> deleteScientificJobFileSource(
      @RequestParam("id") Integer id, HttpServletRequest request, HttpServletResponse response) {
    Map<String, Object> dataMap = new HashMap<String, Object>();
    try {
      if (id != null) {
        // 查询附件表信息
        JkyContributionAtt jkyContributionAtt = jkyContributionAttService.queryByPK(id);
        if (jkyContributionAtt != null) {
          int num = jkyContributionAttService.deleteByPK(jkyContributionAtt);
          if (num >= 1) {
            FileUtil.deleteFile(Constant.UPLOADPATH + "/" + jkyContributionAtt.getFilepath());
          }
        }
      }
      dataMap.put("success", "0000");
    } catch (Exception e) {
      LOGGER.error("调用services网络异常", e);
      dataMap.put("success", "-9999");
    }
    return dataMap;
  }

  /**
   * 
   * 删除年度科研作业信息
   * 
   * @param model
   * @param request
   * @return
   */
  @SysLogger(description = "删除年度科研作业信息", moduleName = "年度科研作业信息", method = "删除")
  @RequestMapping(value = "/deleteScientificJob", method = RequestMethod.POST)
  public String deleteScientificJob(ModelMap model, HttpServletRequest request) {
    try {
      String[] idList = request.getParameter("idList").split(",");
      if (idList.length >= 1) {
        List<JkyContributionAtt> contributionAttList =
            jkyContributionService.deleteForumContributions(idList);
        if (contributionAttList != null && !contributionAttList.isEmpty()) {
          for (JkyContributionAtt att : contributionAttList) {
            FileUtil.deleteFile(Constant.UPLOADPATH + "/" + att.getFilepath());
          }
        }
        BaseController.setParameter("msg", "删除成功");
      } else {
        BaseController.setParameter("msg", "删除失败");
      }
      return "redirect:indexScientificJob";
    } catch (Exception e) {
      LOGGER.error(e.getMessage(), e);
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
  }

  /**
   * 年度科研作业(管理端)
   *
   * @param model
   * @param request
   * @return
   */
  @RequestMapping(value = "/indexManagerScientificJob")
  public String indexManagerScientificJob(ModelMap model, HttpServletRequest request) {
    try {
      request.setAttribute("msg", BaseController.getParameter("msg"));
      BaseController.removeParameter("msg");
    } catch (Exception e) {
      e.printStackTrace();
      return "error/error";
    }
    return "forumContributions/scientificJob_manager_list";
  }

  /**
   * 年度科研作业信息列表（管理端）
   * 
   * @param model
   * @param request
   * @param pageSize
   * @param currentPage
   * @param data
   * @return
   */
  @RequestMapping(value = "/jkyScientificJobManagerList")
  @ResponseBody
  public ResponseResult jkyScientificJobManagerList(ModelMap model, HttpServletRequest request,
      @RequestParam(value = "rows", required = false) String pageSize,
      @RequestParam(value = "page", required = false) String currentPage, JkyContribution data) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    ResponseResult result = new ResponseResult();
    try {
      if (loginType == 2) { // 老师
        UserEmployee userEmployee =
            (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        // data.setCreatorid(userEmployee.getUid());
        Page page = BaseController.getPage(currentPage, pageSize, request, "createtime", "desc");
        data.setOrderField((String) request.getAttribute("orderField"));
        data.setOrderFlag((String) request.getAttribute("orderFlag"));
        PaginationBean<JkyContribution> paginationBean =
            jkyContributionService.queryJkyScientificJobManagerPageList(data, page);
        if (paginationBean.getPageList().isEmpty()) {
          result.setRows(new ArrayList<JkyContribution>());
        } else {
          for (JkyContribution jky : paginationBean.getPageList()) {
            jky.setBeginTime(DateUtil.formatDate2Str(jky.getCreatetime(), "yyyy-MM-dd HH:mm:ss"));
            jky.setName(jky.getCreatorname());
          }
          result.setRows(paginationBean.getPageList());
        }
        result.setTotal(paginationBean.getTotalRecords());
      } else {
        result.setRows(new ArrayList<JkyContribution>());
        result.setTotal(0);
      }
      return result;
    } catch (Exception e) {
      result.setRows(new ArrayList<JkyContribution>());
      result.setTotal(0);
      e.printStackTrace();
      LOGGER.error("年度科研作业信息列表(管理端)信息 jkyScientificJobManagerList [{}] error,"
          + this.getClass().getName() + "=[{}]", this.getClass().getName(), e.getMessage());
    }
    return result;
  }

  /**
   * 
   * 年度科研作业信息 修改跳转页面(管理端)
   * 
   * @param model
   * @param request
   * @param id
   * @return
   */
  @RequestMapping(value = "/modiftyManagerScientificJobForWard", method = RequestMethod.GET)
  public String modiftyManagerScientificJobForWard(ModelMap model, HttpServletRequest request,
      @RequestParam(value = "tgid") Integer id) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    try {
      JkyContribution jkyContribution = new JkyContribution();
      if (loginType == 2) { // 教师
        UserEmployee userEmployee =
            (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        List<JkyContributionAtt> contributionAttList = new ArrayList<JkyContributionAtt>();
        List<JkyContributionReply> contributionReplyList = new ArrayList<JkyContributionReply>();
        if (id != null) {
          jkyContribution = jkyContributionService.queryByPK(id);
          if (jkyContribution != null) {
            contributionAttList = jkyContributionAttService.queryContributionAttList(id);
            contributionReplyList = jkyContributionReplyService.queryContributionReplyList(id);
          }
        }
        model.put("jkyContribution", jkyContribution);
        model.put("contributionAttList", contributionAttList);
        model.put("contributionReplyList", contributionReplyList);
        model.put("msg", BaseController.getParameter("msg"));
        BaseController.removeParameter("msg");
        return "forumContributions/updateManagerScientificJob";
      } else {
        BaseController.setParameter("msg", "没权限访问该页面");
        return "redirect:indexManagerScientificJob";
      }
    } catch (Exception e) {
      LOGGER.error("修改年度科研作业信息（管理端） modiftyManagerScientificJobForWard [{}] error,"
          + this.getClass().getName() + "=[{}]", this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }

  }

  /**
   * 导出年度科研作业信息(管理端)
   * 
   * @param model
   * @param request
   */
  @RequestMapping(value = "/exportManagerScientificJob")
  public String exportManagerScientificJob(ModelMap model, HttpServletRequest request,
      JkyContribution jkyContribution, HttpServletResponse response) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    try {
      String[][] title_name = {{"上传人", "上传日期", "文件数量", "主题", "备注"}};
      String[] title_style = {"hwzs_16_bold_25", "kt_12_bold_18", "st_12_r_20", "st_12_n_20"};
      String fileName = "年度科研作业信息";
      String[] remark = {""};
      List<Map<String, Object>> exportlist = new ArrayList<Map<String, Object>>();
      if (loginType == 2) { // 老师
        UserEmployee userEmployee =
            (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        Page page = BaseController.getPage("0", "0", request, "createtime", "desc");
        jkyContribution.setOrderField((String) request.getAttribute("orderField"));
        jkyContribution.setOrderFlag((String) request.getAttribute("orderFlag"));
        List<JkyContribution> list =
            jkyContributionService.exportScientificJobManagerPageList(jkyContribution);
        if (!list.isEmpty()) {
          for (JkyContribution res : list) {
            Map<String, Object> map = new LinkedHashMap<String, Object>();
            map.put("creatorname", res.getCreatorname());
            map.put("createtime", DateUtil.formatDate2Str(res.getCreatetime(), "yyyy-MM-dd hh:mm"));
            map.put("docnum", res.getDocnum());
            map.put("subject", res.getSubject());
            map.put("remark", res.getRemark());
            exportlist.add(map);
          }
        }
      }
      HSSFWorkbook wb =
          ExpExcelUtil.getWorkBookExcel(title_name, title_style, 100, remark, fileName, exportlist);
      response.reset();
      response.setContentType("application/vnd.ms-excel;charset=utf-8");
      response.setHeader("Content-Disposition",
          "attachment;filename=" + new String((fileName + ".xls").getBytes(), "iso-8859-1"));
      response.setDateHeader("Expires", 0);
      ServletOutputStream os = response.getOutputStream();
      wb.write(os);
      os.flush();
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error("导出年度科研作业信息（管理端） exportManagerContributions [{}] error,"
          + this.getClass().getName() + "=[{}]", this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
    return null;
  }

}
